<template>
  <div class="mininav">
    <div class="topNva"><top-nav /></div>
    <div class="nav">
      <div class="left" />
      <div class="container">
        <router-link class="tab-item" to="/home">首页</router-link>
        <router-link class="tab-item" to="/category" target="_blank">
          包装分类
          <div class="dropdown">
            <ul>
              <li class="dropdownBox" v-for="(item, index) in list1" :key="index" @click="toCateDetails(item.id, item.cate_name, 1)">
                <img class="imgbox" :src="item.pic" alt="" />
                <span>{{ item.cate_name }}</span>
              </li>
            </ul>
          </div>
        </router-link>
        <router-link class="tab-item" to="/industryService/service" target="_blank">
          产业服务
          <div class="dropdown">
            <ul>
              <li class="dropdownBox" v-for="(item, index) in list2" :key="index" @click="toCateDetails(item.id, item.cate_name, 0)">
                <img class="imgbox" :src="item.pic" alt="" />
                <span>{{ item.cate_name }}</span>
              </li>
            </ul>
          </div>
        </router-link>
        <router-link class="tab-item" to="/releaseRequire" target="_blank">发布需求</router-link>
        <router-link class="tab-item" to="/commissionOfficial" target="_blank">委托平台</router-link>
        <router-link class="tab-item" to="/statyService" target="_blank">官方服务</router-link>
        <router-link class="tab-item" to="/demand" target="_blank">需求中心</router-link>
        <router-link class="tab-item" to="/settled" target="_blank">入驻企业</router-link>
        <router-link class="tab-item" to="/exhibition" target="_blank">展览会议</router-link>
      </div>
    </div>
  </div>
</template>

<script>
import searchSelect from '@/components/m-searchbar/SearchSelect';
import TopNav from '@/components/common/topNav/index';
import { getProductsCategory } from '@/request/api';

export default {
  name: 'MiniNav', // 首页的导航条
  components: {
    searchSelect,
    TopNav
  },
  data() {
    return {
      res: '成功添加购物车！',
      search_type: '',
      keywords: '',
      list1: [],
      list2: []
    };
  },
  created() {
    this.getList();
  },
  methods: {
    toHome() {
      this.$router.push({ path: '/home' });
    },
    getList() {
      let data1 = {
        is_entity: '1',
        page: 1,
        limit: 15,
        pid: 0,
        num: 15
      };
      let data2 = {
        is_entity: '0',
        page: 1,
        limit: 15,
        pid: 0,
        num: 15
      };
      getProductsCategory(data1).then(res => {
        this.list1 = res.data.data;
      });
      getProductsCategory(data2).then(res => {
        this.list2 = res.data.data;
      });
    },
    toCateDetails(id, name, type) {
      let path = type == 1 ? '/category/classify/' : '/industryService/service/classify/';
      let routeUrl = this.$router.resolve({
        path: path + id + '?name=' + name,
        query: { t: Date.now() }
      });
      window.open(routeUrl.href, '_blank');
    }
  },
  destroyed() {
    console.log('isdied');
  }
};
</script>

<style lang="scss" scoped>
.mininav {
  position: fixed;
  top: 0;
  z-index: 500;
  background: #e38b2e;
  width: 100%;
}

.nav .search {
  float: left;
  margin-top: 20px;
}

.nav {
  width: 100%;
  height: auto;
  font-size: 14px;
  color: #fff;
  margin: 0 auto;
  position: relative;
}

.nav .container {
  line-height: 55px;
  background: #e38b2e;
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 1200px;
  margin: 0 auto;
}

.nav .container .tab-item {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

.nav .container .tab-item:hover {
  color: #e38b2e;
  background: #fcd4a0;
}

.container .router-link-active {
  color: #e38b2e;
  background: #fcd4a0;
}

.nav .container .tab-item::after {
  content: '';
  width: 1px;
  height: 32px;
  background: #fff;
  position: absolute;
  right: 0;
  top: 16px;
  opacity: 0.4;
}

.nav .container .tab-item:last-of-type::after {
  display: none;
}

.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
}

.nav .left {
  position: absolute;
  left: 20px;
  bottom: 15px;
}

.nav .left img {
  width: 220px;
}

.right {
  margin-top: 20px;
  float: right;
  width: 200px;
  height: 60px;
}

.icon {
  display: flex;
}

.icon a {
  flex: 1;
  display: flex;
  flex-direction: column;
  text-align: center;
  justify-content: center;
  align-items: center;
}

.icon a {
  color: #000;
}

.icon a.active {
  color: #e38b2e;
}

.icon a:hover {
  color: #e38b2e;
}

.icon a img {
  width: 20px;
  height: 23px;
  margin-bottom: 6px;
}
.tab-item:hover .dropdown {
  display: block;
}
.dropdown {
  display: none;
  width: 1100px;
  background-color: #ffffff;
  padding: 5px 10px;
  position: absolute;
  left: -83px;
  top: 55px;
  z-index: 110;
  .dropdownBox {
    float: left;
    width: 212px;
    height: 90px;
    margin: 2px 2px;
    background-color: #f3f4f7;
    border: 1px #eee solid;
    box-sizing: border-box;
    cursor: pointer;

    .imgbox {
      width: 100px;
      height: 100%;
      float: left;
    }

    span {
      display: flex;
      align-items: center;
      justify-content: center;
      float: right;
      color: #7e7e7f;
      font-size: 14px;
      font-weight: bold;
      width: 100px;
      height: 100%;
      line-height: 1.5;
      padding: 10px;
    }
  }

  .dropdownBox:hover {
    border: 1px solid #f2f2f2;
    box-sizing: border-box;
  }

  .dropdownBox:hover span {
    color: #e38b2e;
  }
}
.nav .container .tab-item:nth-of-type(3) .dropdown {
  left: -216px;
}
</style>
